
package ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import Utils.StringUtil;
import base.BaseViewHolder;
import base.SuperBaseAdapter;
import coom.Constants;
import ui.activity.wallet.RewardsDetailsAct;
import ui.activity.wallet.RewardsDetailsOtherAct;
import ui.model.RewardsDetailsBean;


/**
 * 新钱包奖励适配器
 * Created by chenjian on 19/2/27.
 */
public class RewardsSummaryAdapter extends SuperBaseAdapter<RewardsDetailsBean> {

    List<RewardsDetailsBean> mData = new ArrayList<>();
    Context mContext;
    int mType = 1;

    public RewardsSummaryAdapter(Context context, List<RewardsDetailsBean> data, int type) {
        super(context, data);
        mContext = context;
        mData = data;
        mType = type;
    }

    @Override
    protected void convert(BaseViewHolder holder, final RewardsDetailsBean item, final int position) {
        TextView time = holder.getView(R.id.item_rewards_summary_time);
        TextView title = holder.getView(R.id.item_rewards_summary_title);
        TextView money = holder.getView(R.id.item_rewards_summary_money);
        View line = holder.getView(R.id.view_line);

        time.setText(item.getYear() + "." + item.getMonth());
        money.setText("奖励金额：" + StringUtil.getFormatPrice(item.getAmount()) + "元");
        if (mData.size() > 0) {
            line.setVisibility(position == (mData.size() - 1) ? View.VISIBLE : View.GONE);
        }
        switch (mType) {
            case 1://购买奖
                title.setText("购买台数：" + item.getSnCount() + "台");
                break;
            case 2://推广奖
                title.setText("推广台数：" + item.getSnCount() + "台");
                break;
            case 3://培养奖
                title.setText("采购台数：" + item.getSnCount() + "台");
                break;
            case 4://会员奖
                title.setText("购买会员：" + item.getRecordCount() + "份");
                break;
            case 5://成长奖
                title.setText("激活台数：" + item.getSnCount() + "台");
                break;
            case 6://挑战奖
                title.setText("商户数：" + item.getRecordCount() + "个");
                break;
            case 7://导师奖
                title.setText("开通商户：" + item.getRecordCount() + "个");
                break;
            default:
                break;
        }

        holder.getView(R.id.item_rewards_summary_check).setOnClickListener(v -> {
            Intent intent = null;
            if (mType == 3) {
                intent = new Intent(mContext, RewardsDetailsOtherAct.class);
                intent.putExtra(Constants.KEY, item);
            } else {
                intent = new Intent(mContext, RewardsDetailsAct.class);
                intent.putExtra(Constants.KEY, item);
            }
            if (intent != null) {
                mContext.startActivity(intent);
            }
        });
    }


    @Override
    protected int getItemViewLayoutId(int position, RewardsDetailsBean item) {
        return R.layout.item_rewards_summary;
    }
}
